﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace ERP.BusinessEntities.Util
{
    public class StandardReflect:IReflectUtil
    {
        public object GetProperty(object obj, string strPropName)
        {
            var prop = obj.GetType().GetProperty(strPropName);
            return GetProperty(obj, prop);
        }
        public object GetProperty(object obj, System.Reflection.PropertyInfo prop)
        {
            return prop.GetValue(obj, null);
        }
        public object GetProperty(object obj, FieldInfo fld)
        {
            Type type = obj.GetType();
            return GetProperty(obj, type, fld);
        }
        public object GetProperty(object obj, Type type, System.Reflection.PropertyInfo prop)
        {
            return prop.GetValue(obj, null);
        }
        public object GetProperty(object obj, Type type, FieldInfo fld)
        {
            return fld.GetValue(obj);
        }

        public void SetProperty(object obj, string strPropName, object value)
        {

            var prop = obj.GetType().GetProperty(strPropName);
            prop.SetValue(obj, value, null);
        }
        public void SetProperty(object obj, System.Reflection.PropertyInfo prop, object value)
        {
            prop.SetValue(obj, value, null);
        }
        public void SetProperty(object obj, Type type, PropertyInfo prop, object value)
        {
            prop.SetValue(obj, value, null);
        }
        public void SetProperty(object obj, Type type, FieldInfo fld, object value)
        {
            fld.SetValue(obj, value);
        }

        public object CreateInstance(String strType)
        {
            Type type = Type.GetType(strType);
            return CreateInstance(type);
        }
        public object CreateInstance(Type type)
        {
            return Activator.CreateInstance(type);
        }
    }
}
